package com.glela.controller;

import com.glela.firewall.service.FirewallService;
import com.glela.firewall.util.FirewallConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/firewall")
public class FirewallController {
    private static Logger logger = LoggerFactory.getLogger(FirewallController.class);

    @Autowired
    private FirewallService firewallService;

    @RequestMapping(value = "/loadConfigFile", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String loadConfigFile() {
        try {
            firewallService.reloadFirewallFile();
            return "SUCCESS. " + FirewallConfig.show();
        } catch (Exception e) {
            logger.error("加载防火墙配置文件出错", e);
            return "ERROR. Load firewall config file error:" + e.getMessage();
        }
    }
}
